// File PlayerStates.cpp
//
// Purpose: Contains the states for the player
//
// Author : Bryson King (edited)
// Original Code Provided by: Mat Buckland 2002 (fup@ai-junkie.com)
// Date : 18 March 2013
// --------------------------------------------------------------
#include "PlayerStates.h"
#include "AbstractState.h"
#include "Player.h"
#include "Telegram.h"
#include "MessageDispatcher.h"
#include "MessageTypes.h"
#include "Time/CrudeTimer.h"
#include "EntityNames.h"

#include <iostream>
using std::cout;
using std::endl;

//------------------------------------------------------------------------methods for Startup
Startup* Startup::Instance()
{
	static Startup instance;
	return &instance;
}

void Startup::Enter(CPlayer* pTerrorist)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Entering the Startup state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

void Startup::Execute(CPlayer* pTerrorist)
{
	//if terrorist's health drops less than 25%, run away
	if (pTerrorist->Health() < (.25 * MaxHealthLevelForPlayer))
	{
		pTerrorist->GetFSM()->ChangeState(Startup::Instance());
	}

	//if health not an issue, attack enemies in range
	//ALL ENEMIES IN SAME SPACE ARE IN RANGE
	
	//if no enemies in range, proceed toward the bridge
	if (true)
	{
		pTerrorist->GetFSM()->ChangeState(Startup::Instance());
	}
}

void Startup::Exit(CPlayer* pTerrorist)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Exiting the Startup state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

bool Startup::OnMessage(CPlayer* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}
/*
//------------------------------------------------------------------------methods for RunAway

RunAway* RunAway::Instance()
{
	static RunAway instance;
	return &instance;
}

void RunAway::Enter(CPlayer* pTerrorist)
{  
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Entering the RunAway state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

void RunAway::Execute(CPlayer* pTerrorist)
{
	//if no enemies around, stop running away and hide until healed
	if (true)
	{
		pTerrorist->GetFSM()->ChangeState(Hide::Instance());
	}

	//if health at 75% or more, proceed to bridge
	if (pTerrorist->Health() >= (.75 * MaxHealthLevel))
	{
		pTerrorist->GetFSM()->ChangeState(ProceedTowardBridge::Instance());
	}
}

void RunAway::Exit(CPlayer* pTerrorist)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Exiting the RunAway state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

bool RunAway::OnMessage(CPlayer* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}
//------------------------------------------------------------------------methods for ProceedTowardBridge

ProceedTowardBridge* ProceedTowardBridge::Instance()
{
	static ProceedTowardBridge instance;
	return &instance;
}

void ProceedTowardBridge::Enter(CPlayer* pTerrorist)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Entering the ProceedTowardBridge state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

void ProceedTowardBridge::Execute(CPlayer* pTerrorist)
{
	//attack enemy if stronger than enemy
	if (true)
	{
		pTerrorist->GetFSM()->ChangeState(Attack::Instance());
	}

	//hide from enemy if weaker than enemy
	if (false)
	{
		pTerrorist->GetFSM()->ChangeState(Hide::Instance());
	}
}

void ProceedTowardBridge::Exit(CPlayer* pTerrorist)
{ 
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Exiting the ProceedTowardBridge state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}


bool ProceedTowardBridge::OnMessage(CPlayer* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}

//------------------------------------------------------------------------methods for Hide

Hide* Hide::Instance()
{
	static Hide instance;
	return &instance;
}

void Hide::Enter(CPlayer* pTerrorist)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Entering the Hide state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

void Hide::Execute(CPlayer* pTerrorist)
{
	//if no enemies around, stop running away and wait until healed
	if (true)
	{
		pTerrorist->SetHealth(HealthHealedPerTick + pTerrorist->Health());
	}

	//if health returned to 75%, go back to previous proceeding toward the bridge
	if (pTerrorist->Health() >= (.75 * MaxHealthLevel))
	{
		pTerrorist->GetFSM()->ChangeState(ProceedTowardBridge::Instance());
	}
}


void Hide::Exit(CPlayer* pTerrorist)
{ 
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Exiting the Hide state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}


bool Hide::OnMessage(CPlayer* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}

//------------------------------------------------------------------------methods for Hijack

Hijack* Hijack::Instance()
{
	static Hijack instance;
	return &instance;
}


void Hijack::Enter(CPlayer* pTerrorist)
{
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Entering the Hijack state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}

void Hijack::Execute(CPlayer* pTerrorist)
{
	//if health < 25%, run away
	if (pTerrorist->Health() < (.25 * MaxHealthLevel))
	{
		pTerrorist->GetFSM()->ChangeState(RunAway::Instance());
	}

	//if bridge control successful
	if (true)
	{
		//win the game!!!
	}
}

void Hijack::Exit(CPlayer* pTerrorist)
{ 
	#ifdef DEBUG_SECTION
		// Output status of the terrorist
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Exiting the Hijack state";
		cout << endl << GetNameOfEntity(pTerrorist->ID()) << ": " << "Health is currently at " << 
			pTerrorist->Health();
	#endif
}


bool Hijack::OnMessage(CPlayer* agent, const Telegram& msg)
{
	//send msg to global message handler
	return false;
}


*/